from PyQt4 import QtCore,QtGui
from lista_comandos import Lista_Comandos

class Linha_comando(QtGui.QLineEdit):
    def __init__(self, *args):
        QtGui.QLineEdit.__init__(self, *args)
        self.lista_comandos = Lista_Comandos()
        
    def uppress(self):
        self.setText(self.lista_comandos.next())

    def downpress(self):
        self.setText(self.lista_comandos.prev())
        
    def addcommand(self, text):
        self.lista_comandos.addlast(text)

    def event(self, event):
        if (event.type()==QtCore.QEvent.KeyPress) and (event.key()==QtCore.Qt.Key_Down):
            #self.emit(QtCore.SIGNAL("downpressed()"))
            self.downpress()
            return True
        if (event.type()==QtCore.QEvent.KeyPress) and (event.key()==QtCore.Qt.Key_Up):
            self.uppress()
            #self.emit(QtCore.SIGNAL("uppressed()"))
            return True
        #if (event.type()==QtCore.QEvent.FocusIn):
            #self.setStyleSheet("background-color: rgb(200, 200, 255);")
            #self.setStyleSheet("background-color: rgb(00, 00, 5);")
            #return True
        #if (event.type()==QtCore.QEvent.FocusOut):
            #self.setStyleSheet("")
            #return True
        return QtGui.QLineEdit.event(self, event)

